package com.cjm.algorithm.leetcode;

import java.util.HashMap;
import java.util.Map;

public class FourSumCount454 {
    public static int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums3.length; i++) {
            for (int i1 = 0; i1 < nums4.length; i1++) {
                int sum = nums3[i] + nums4[i1];
                Integer integer = map.get(sum);
                if (integer != null) {
                    map.put(sum, ++integer);
                } else {
                    map.put(sum, 1);
                }
            }
        }
        int count = 0;
        for (int i = 0; i < nums1.length; i++) {
            for (int i1 = 0; i1 < nums2.length; i1++) {
                Integer integer = map.get(-nums1[i] - nums2[i1]);
                if (integer != null) count += integer;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.err.println(fourSumCount(new int[]{1, 2}, new int[]{-2, -1}, new int[]{-1, 2}, new int[]{0, 2}));
        System.err.println(fourSumCount(new int[]{0}, new int[]{0}, new int[]{0}, new int[]{0}));
    }
}
